package com.wyq.jpa.service;

import com.itiancai.thirdpart.zbank.tsp.ZbankClient;
import com.itiancai.thirdpart.zbank.tsp.model.GetcodeBusType;
import com.itiancai.thirdpart.zbank.tsp.model.GetcodeRequest;
import org.apache.commons.dbcp.BasicDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.wyq.jpa.dao.UserDao;
import com.wyq.jpa.model.User;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class UserService {

	Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	BasicDataSource dataSource;

	ExecutorService executorService = Executors.newSingleThreadExecutor();

	@Autowired
	private UserDao userdao;
	@Autowired
	private LinkService linkService;

	@Autowired
	@Qualifier("zbankClient")
	private ZbankClient client;

	/*@PostConstruct
	public void setUp(){
		executorService.execute(new Runnable() {
			@Override
			public void run() {
				while (true) {
					logger.info("start......" );
					logger.info("最大链接==>" + dataSource.getMaxActive() + "");
					logger.info("活动链接==>" + dataSource.getNumActive() + "");
					logger.info("空闲链接==>" + dataSource.getNumIdle() + "");
					linkService.getLinks();
					linkService.insert1();
					logger.info("end......");
					try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					logger.info("before restart......");
				}
			}
		});
	}*/
	
	public boolean check(String userName,String password){
		User user=userdao.findByName(userName);
		if(user!= null&& user.getPassword().equals(password)){
			return true;
		}
		return false;
	}

	@Transactional
	public void all() {
		GetcodeRequest request = new GetcodeRequest();
		request.setBusType(GetcodeBusType.QT);
		request.setOrderId("test002");
		request.setPhoneNo("18611135863");
		request.setVersionNo("1.00");
		client.verifycodeGetcode(request);
		linkService.insert();
	}
}
